import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Scanner;

public class example2 {
    public static void main(String[] args) {
        ArrayList<Student> array = new ArrayList<Student>();

        while (true){
            System.out.println("欢迎来到学生管理系统");
            System.out.println("1 查看所有学生");
            System.out.println("2 添加学生");
            System.out.println("3 删除学生");
            System.out.println("4 修改学生");
            System.out.println("5 退出");
            System.out.println("请输入你的选择：");

            Scanner sc = new Scanner(System.in);
            String choiceString = sc.nextLine();

            switch (choiceString) {
                case "1":
                    //查看所有的学生
                    findAllStudent(array);
                    break;
            }
        }
    }

    public static void findAllStudent(ArrayList<Student> array) {
        //
        if (array.size() == 0) {
            System.out.println("不好意思，目前没有学生信息可供查询");
            return;
        }
        System.out.println("学号\t姓名\t年龄\t居住地\t");
        for (int x = 0; x < array.size(); x++) {
            Student s = array.get(x);
            System.out.println(s.getId()+"\t"+s.getName()+"\t"+s.getAge()
            + "\t" + s.getAddress());
        }
    }

    public static void addStudent(ArrayList<Student> array) {
        Scanner sc = new Scanner(System.in);

        String id;

        while(true) {
            System.out.println("请输入学生学号");
            id = sc.nextLine();
            boolean flag = false;

            for (int x = 0; x < array.size(); x++) {
                Student s = array.get(x);
                if (s.getId().equals(id)) {
                    flag = true;
                    break;
                }
            }
            if (flag) {
                System.out.println("学号被占用");
            } else {
                break;
            }

        }
        System.out.println("请输入学生姓名：");
        String name = sc.nextLine();
        System.out.println("请输入学生年龄：");
        String age = sc.nextLine();
        System.out.println("请输入学生居住地：");
        String address = sc.nextLine();

        Student student = new Student();
        student.setAge(age);
        student.setAddress(address);
        student.setName(name);
        array.add(student);
        System.out.println("添加学生成功。");
    }
}
